package com.jeff.android.lab.bugs.toast;

import android.widget.Toast;

import com.jeff.android.lab.BaseFragment;
import com.jeff.android.lab.R;
import com.jeff.android.lab.bugs.toast.repair.ToastUtil;

import butterknife.OnClick;

/**
 * @author: dingfeng
 * @date: 2020-04-14
 * @since: 1.0.0
 **/
public class ToastBugFragment extends BaseFragment {

    @Override
    protected int getRootLayout() {
        return R.layout.bug_toast_fragment;
    }

    /**
     * android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@ac94150 is not valid; is your activity running?
     *     at android.view.ViewRootImpl.setView(ViewRootImpl.java:746)
     *     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:366)
     *     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:119)
     *     at android.widget.Toast$TN.handleShow(Toast.java:466)
     *     at android.widget.Toast$TN$2.handleMessage(Toast.java:345)
     *     at android.os.Handler.dispatchMessage(Handler.java:102)
     *     at android.os.Looper.loop(Looper.java:154)
     *     at android.app.ActivityThread.main(ActivityThread.java:6179)
     *     at java.lang.reflect.Method.invoke(Method.java)
     *     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
     *     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
     * */
    @OnClick(R.id.btn_recurrent)
    public void recurrentAndroidNToastBug() {
        Toast.makeText(mContext, "尝试复现 Bug", Toast.LENGTH_LONG).show();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @OnClick(R.id.btn_repair)
    public void repairAndroidNToastBug() {
        ToastUtil.show(mContext, "尝试复现 Bug");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
